package com.eightbears.beboy.ui.user.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.eightbears.beboy.R;
import com.eightbears.beboy.base.BaseActivity;
import com.eightbears.beboy.base.view.SwipeBackLayout;
import com.eightbears.beboy.ui.user.fragment.BuyPostFragment;
import com.eightbears.beboy.ui.user.fragment.CollectPostFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyPostActivity extends BaseActivity {

    @BindView(R.id.sw_finish)
    SwipeBackLayout sw_finish;
    @BindView(R.id.tv_tab_left_text)
    TextView tv_tab_left_text;
    @BindView(R.id.tv_tab_right_text)
    TextView tv_tab_right_text;
    @BindView(R.id.view_left_line)
    View view_left_line;
    @BindView(R.id.view_right_line)
    View view_right_line;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_post);

        initView();
        initData();
        initEvent();
    }

    @Override
    protected void initView() {
        ButterKnife.bind(this);
        tv_tab_left_text.setSelected(true);
        view_left_line.setSelected(true);
    }

    @Override
    protected void initData() {
        buyPost();
    }

    @Override
    protected void initEvent() {
        sw_finish.setCallBack(new SwipeBackLayout.CallBack() {
            @Override
            public void onFinish() {
                finish();
            }
        });
    }

    /**
     * 已购买
     */
    @OnClick(R.id.ll_tab_left)
    void buyPost() {
        selectLeft();
        replaceFragment(R.id.frame_container, new BuyPostFragment());
    }

    /**
     * 已收藏
     */
    @OnClick(R.id.ll_tab_right)
    void collectPost() {
        selectRight();
        replaceFragment(R.id.frame_container, new CollectPostFragment());
    }

    @OnClick(R.id.ll_back)
    void back() {
        finish();
    }

    private void selectLeft() {
        replaceView();
        tv_tab_left_text.setSelected(true);
        view_left_line.setSelected(true);
    }

    private void selectRight() {
        replaceView();
        tv_tab_right_text.setSelected(true);
        view_right_line.setSelected(true);
    }

    private void replaceView() {
        tv_tab_left_text.setSelected(false);
        view_left_line.setSelected(false);
        tv_tab_right_text.setSelected(false);
        view_right_line.setSelected(false);
    }
}
